from django.db import models

# Create your models here.

class Article(models.Model):                          #文章表
    a_cover = models.ImageField(upload_to='static/images')          #封面
    a_title = models.CharField(max_length=40)           #标题
    a_author = models.CharField(max_length=20)          #作者
    a_abstract = models.CharField(max_length=640)       #摘要
    a_content = models.CharField(max_length=9999)       #内容
    a_date = models.DateField(auto_now=True)            #日期
    a_isDelete = models.BooleanField(default='False')                 #是否删除，默认为否
    user = models.ForeignKey("User", on_delete=models.CASCADE)        #外键约束user
    city = models.ForeignKey('City', on_delete=models.CASCADE)        #city
    classify = models.ManyToManyField(to="Classify")
    site =models.ForeignKey('Site',on_delete=models.CASCADE)

    class Meta:
        db_table = 'article'


class User(models.Model):                           #用户表
    u_user = models.CharField(max_length=20)            #帐号
    u_password = models.CharField(max_length=100)        #密码
    u_perssions = models.CharField(max_length=20)       #权限
    u_username = models.CharField(max_length=20)       #用户名字（网名）
    u_email = models.EmailField(default='')            #用户网址
    u_tel = models.CharField(max_length=11)            #用户手机
    u_addr = models.CharField(max_length=100)          #用户地址

    class Meta:
        db_table = 'user'


class Classify(models.Model):                       #分类表
    cl_name = models.CharField(max_length=40)       #分类名字

    site = models.ForeignKey('Site',on_delete=models.CASCADE)

    class Meta:
        db_table = 'classify'

class City(models.Model):                       #地区表
    ci_name = models.CharField(max_length=20)   #地区名字

    class Meta:
        db_table = 'city'


class Score(models.Model):                              #积分表
    s_score = models.IntegerField()                     #积分总数
    s_date = models.DateField(auto_now=True)            #日期
    s_num = models.IntegerField()                       #单次充值积分数
    s_way = models.CharField(max_length=40,default='3')       #充值方式：3为管理员代冲
    user = models.ForeignKey('User',on_delete=models.CASCADE)

    class Meta:
        db_table = 'score'


class Site(models.Model):                   #站点
    si_name = models.CharField(max_length=50)           #站点名字
    si_web = models.CharField(max_length=50)            #站点网址
    si_score = models.IntegerField()                    #使用站点积分

    class Meta:
        db_table = 'site'
